package com.jy.adscm.operation.pebase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.operation.pebase.bean.PeDocument;
import com.jy.adscm.operation.pebase.bean.PeDocumentLabel;
import com.jy.adscm.operation.pebase.bean.PeLabel;
import com.jy.adscm.operation.pebase.mapper.mysql.PeDocumentLabelMapper;
import com.jy.adscm.operation.pebase.mapper.mysql.PeLabelMapper;
import com.jy.adscm.operation.pebase.service.PeLabelService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-04-18
 */
@Service
public class PeLabelServiceImpl extends ServiceImpl<PeLabelMapper, PeLabel> implements PeLabelService {
@Autowired
    PeDocumentLabelMapper peDocumentLabelMapper;
@Autowired
PeLabelMapper peLabelMapper;
    @Override
    public boolean deletepeLabel(Integer id) {
        //先删除与他建立关系的文档
        Wrapper<PeDocumentLabel> peDocumentLabelWrapper=new EntityWrapper<>();
        peDocumentLabelWrapper.eq("lid",id);
        List<PeDocumentLabel> peDocumentLabels = peDocumentLabelMapper.selectList(peDocumentLabelWrapper);
        if (peDocumentLabels!=null&&peDocumentLabels.size()>0){
            for (PeDocumentLabel peDocumentLabel : peDocumentLabels) {
                peDocumentLabelMapper.deleteById(peDocumentLabel.getId());
            }
        }

        Integer integer = peLabelMapper.deleteById(id);
        boolean result=false;
        if (integer==1){
            result=true;
        }
        return result;
    }
}
